﻿
@{
    ViewBag.Title = "用户管理";
    Layout = "~/Areas/Control/Views/Shared/_Layout.cshtml";
}

@section SideNav{@Html.Partial("SideNavPartialView")}

<ol class="breadcrumb">
    <li><span class="glyphicon glyphicon-home">@Html.ActionLink("首页","Index","Home")</span></li>
    <li class="active">@Html.ActionLink("用户管理","Index","User")</li>
</ol>

<table id="usergrid"></table>
@section style{
    @Styles.Render("~/Content/bootstrapplugincss")
}

@section scripts{
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/bootstrapplugin")
    <script type="text/javascript">
        $(document).ready(function () {
            //表格
            var $table = $('#usergrid');
            $table.bootstrapTable({
                showRefresh: true,
                showColumns: true,
                pagination: true,
                sidePagination: "server",
                pageList: "[5,10,20,50,100]",
                method: "post",
                url: "@Url.Action("PageListJson")",
                columns: [
                    { title: "ID", field: "UserID" },
                    { title: "角色", field: "RoleID" },
                    { title: "用户名", field: "Username" },
                    { title: "名称", field: "Name", formatter: function (value, row, index) { return "<a href='@Url.Action("Modify","User")/"+row.UserID+"'>"+value+"</a>"}},
                    { title: "性别", field: "Sex" },
                    { title: "Email", field: "Email", visible: false },
                    { title: "最后登录时间", field: "LastLoginTime", formatter: function (value) { return moment(value).format("YYYY-MM-DD HH:mm:ss") } },
                    { title: "最后登录IP", field: "LastLoginIP", visible: false },
                    { title: "注册时间", field: "RegTime",  formatter: function (value) { return moment(value).format("YYYY-MM-DD HH:mm:ss") } },
                    { title: "操作", field: "UserID", formatter: function (value) { return "<a class='btn btn-sm btn-danger' data-operation='deleteuser' data-value='" + value + "'>删除</a>" } }
                ],
                onLoadSuccess: function () {
                    //删除按钮
                    $("a[data-operation='deleteuser']").click(function () {
                        var id = $(this).attr("data-value");
                        BootstrapDialog.confirm("你确定要删除" + $(this).parent().parent().find("td").eq(3).text() + "吗？\n建议尽可能不要删除用户。", function (result) {
                            if (result) {
                                $.post("@Url.Action("Delete","User")", { id: id }, function (data) {
                                    if (data.Code == 1) {
                                        BootstrapDialog.show({
                                            message: "删除用户",
                                            buttons: [{
                                                icon: "glyphicon glyphicon-ok",
                                                lable: "确定",
                                                action: function (dialogItself) {
                                                    $table.bootstrapTable("refresh");
                                                    dialogItself.close();
                                                }
                                            }]
                                        });
                                    }
                                    else BootstrapDialog.alert(data.Message);
                                }, "json");
                            }
                        });
                    });
                    //删除按钮结束
                }
            });
            //表格结束
        });
    </script>
}